package org.spiderflow.common.concurrent;

/**
 * @author zhaoshihao
 * @version 2021/10/28 14:21
 */
public class ThreadSubmitStrategyFactory {
    private ThreadSubmitStrategyFactory() {
    }

    /**
     * 选择提交策略，这里一定要使用new,不能与其他实例共享
     *
     * @param strategy 策略
     * @return 提交策略
     */
    public static ThreadSubmitStrategy createStrategy(String strategy) {
        if (LinkedThreadSubmitStrategy.isMatch(strategy)) {
            return new LinkedThreadSubmitStrategy();
        } else if (ChildPriorThreadSubmitStrategy.isMatch(strategy)) {
            return new ChildPriorThreadSubmitStrategy();
        } else if (ParentPriorThreadSubmitStrategy.isMatch(strategy)) {
            return new ParentPriorThreadSubmitStrategy();
        } else {
            return new RandomThreadSubmitStrategy();
        }
    }
}
